{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "eae7aa32-69c3-4f28-8429-101fafc3bfee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.47.0.dev0\n"
     ]
    }
   ],
   "source": [
    "import bitsandbytes as bnb\n",
    "print(bnb.__version__)  # 应输出 0.47.0.dev0"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "729a8105-352e-40db-b1a4-25afbfae5f51",
   "metadata": {},
   "source": [
    "(2) 测试核心功能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "62e668f5-daad-49fa-880a-a6f8a581b709",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'bitsandbytes' has no attribute '__CUDA_ENABLED__'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[8], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 测试 CUDA 是否可用（需GPU环境）\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mbnb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__CUDA_ENABLED__\u001b[49m)  \u001b[38;5;66;03m# 返回 True/False\u001b[39;00m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;66;03m# 测试8位优化器\u001b[39;00m\n\u001b[1;32m      4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mtorch\u001b[39;00m\n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'bitsandbytes' has no attribute '__CUDA_ENABLED__'"
     ]
    }
   ],
   "source": [
    "# 测试 CUDA 是否可用（需GPU环境）\n",
    "print(bnb.__CUDA_ENABLED__)  # 返回 True/False\n",
    "# 测试8位优化器\n",
    "import torch\n",
    "optimizer = bnb.optim.Adam8bit(torch.randn(10).cuda(), lr=0.01)\n",
    "optimizer.step()  # 无报错则基础功能正常"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3800a08f-7c23-4bf5-a457-cba535604946",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'bitsandbytes' has no attribute 'has_cuda'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mbnb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhas_cuda\u001b[49m()) \n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'bitsandbytes' has no attribute 'has_cuda'"
     ]
    }
   ],
   "source": [
    "print(bnb.has_cuda()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "764e2235-14c6-4973-a780-4f25d6371c8b",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'bitsandbytes' has no attribute 'get_cuda_devices'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[10], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 检查CUDA设备信息\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mbnb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_cuda_devices\u001b[49m())  \u001b[38;5;66;03m# 返回可用GPU列表\u001b[39;00m\n\u001b[1;32m      4\u001b[0m \u001b[38;5;66;03m# 检查CUDA运行时库路径\u001b[39;00m\n\u001b[1;32m      5\u001b[0m \u001b[38;5;28mprint\u001b[39m(bnb\u001b[38;5;241m.\u001b[39mget_cuda_lib_path())  \u001b[38;5;66;03m# 显示链接的CUDA库位置\u001b[39;00m\n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'bitsandbytes' has no attribute 'get_cuda_devices'"
     ]
    }
   ],
   "source": [
    "# 检查CUDA设备信息\n",
    "print(bnb.get_cuda_devices())  # 返回可用GPU列表\n",
    "\n",
    "# 检查CUDA运行时库路径\n",
    "print(bnb.get_cuda_lib_path())  # 显示链接的CUDA库位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ac976d6d-1fef-41a4-923c-1fa71e239c5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可用GPU数量: 1\n",
      "当前GPU: 0\n",
      "设备名称: NVIDIA GeForce GTX 1650\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "module 'bitsandbytes' has no attribute 'COMPILED_WITH_CUDA'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[13], line 8\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m设备名称: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtorch\u001b[38;5;241m.\u001b[39mcuda\u001b[38;5;241m.\u001b[39mget_device_name(\u001b[38;5;241m0\u001b[39m)\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m      7\u001b[0m \u001b[38;5;66;03m# 检查bitsandbytes编译选项\u001b[39;00m\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m编译时CUDA支持: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[43mbnb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mCOMPILED_WITH_CUDA\u001b[49m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)  \u001b[38;5;66;03m# 新属性名\u001b[39;00m\n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'bitsandbytes' has no attribute 'COMPILED_WITH_CUDA'"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "# 检查CUDA设备数量（通过PyTorch）\n",
    "print(f\"可用GPU数量: {torch.cuda.device_count()}\")\n",
    "print(f\"当前GPU: {torch.cuda.current_device()}\")\n",
    "print(f\"设备名称: {torch.cuda.get_device_name(0)}\")\n",
    "\n",
    "# 检查bitsandbytes编译选项\n",
    "print(f\"编译时CUDA支持: {bnb.COMPILED_WITH_CUDA}\")  # 新属性名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "577fb667-867d-4daa-a972-f18e19885a10",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce2d38ba-3eb3-4738-b301-bc41fe243b26",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "deepseek(py310cu118torch25)",
   "language": "python",
   "name": "deepseek"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
